/**
 * UserForm.java
 *
 *
 * $LastChangedBy:  $
 * $LastChangedDate: $
 * $Revision:  $
 */
package com.myspace.view.user;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;

import com.myspace.domain.User;
import com.myspace.common.util.Formatter;

public class UserForm extends ActionForm {
	private static final long serialVersionUID = 1L;

	private User user = new User();

	private FormFile photo;

	private String newpassword = "";

	public String getNewpassword() {
		return newpassword;
	}

	public void setNewpassword(String newpassword) {
		this.newpassword = newpassword;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public void setBirthday(String birthday) throws ParseException {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		this.user.setBirthday(dateFormat.parse(birthday));
	}

	public String getBirthday() {
		if (user == null || this.user.getBirthday() == null) {
			return "1992-01-01";
		}
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		return dateFormat.format(this.user.getBirthday());
	}

	public FormFile getPhoto() {
		return photo;
	}

	public void setPhoto(FormFile photo) {
		this.photo = photo;
	}

	public String getYear() {
		String strDate = Formatter.formatYYYYMMDD(this.getUser().getBirthday());
		return strDate.split("/")[0];
	}

	public String getMonth() {
		String strDate = Formatter.formatYYYYMMDD(this.getUser().getBirthday());
		return strDate.split("/")[1];
	}

	public String getDay() {
		String strDate = Formatter.formatYYYYMMDD(this.getUser().getBirthday());
		return strDate.split("/")[2];
	}

}
